
from rest_framework.views import APIView
from rest_framework.response import Response
from meiduo_admin.serializers.login_serializers import *

# 登陆视图
class LoginView(APIView):

    def post(self, request):
        # 1、提取参数：request.data
        # 2、实例化序列化器对象
        serializer = LoginSerializer(data=request.data)
        # 3、启动校验
        serializer.is_valid(raise_exception=True)
        # 4、构建响应
        user = serializer.validated_data['user']
        token = serializer.validated_data['token']
        return Response({
            'username': user.username,
            'user_id': user.id,
            'token': token
        })